package com.mstar.qs.common.bean;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Comparator;

import com.morningstar.qs.api.basic.util.DatetimeUtil;
import com.morningstar.qs.api.basic.util.DatetimeUtil.DatetimeMetadata;

public class CommonMarket implements Serializable, Comparator {

	protected int exchId;
	protected int secuType;
	protected String marketName;
	protected Integer derivedMarkId;
	protected Integer derivedSecuType;
	protected Integer openMinute;
	protected Integer closeMinute;
	protected Integer preOpenMinute;
	protected Integer afterHourMinute;
	protected short isInternational;

	public CommonMarket() {}

	public CommonMarket(int exchId, int secuType) {
		this.exchId = exchId;
		this.secuType = secuType;
	}

	public String returnMarketInfo() {
		StringBuilder sb = new StringBuilder();
		sb.append("exchId:").append(exchId).append("\t");
		sb.append("secuType:").append(secuType).append("\t");
		sb.append("derivedExchId:").append(derivedMarkId).append("\t");
		sb.append("derivedSecuType:").append(derivedSecuType).append("\t");
		sb.append("openTime:").append(openMinute).append("\t");
		sb.append("closeTime:").append(closeMinute).append("\t");
		sb.append("preOpenTime:").append(preOpenMinute).append("\t");
		sb.append("afterHourTime:").append(afterHourMinute).append("\t");
		sb.append("marketName:").append(marketName).append("\t");
		sb.append("isInternational:").append(isInternational).append("\t");
		return sb.toString();
	}

	public boolean duringTradingHours(String timezoneId) {
		Calendar c = DatetimeUtil.getCalendar(timezoneId);
		int hour = c.get(Calendar.HOUR_OF_DAY);
		int minute = c.get(Calendar.MINUTE);
		int a = hour * 60 + minute;
		return a >= openMinute && a <= closeMinute;
	}
	
	
	public Integer getDerivedMarkId() {
		return derivedMarkId;
	}

	public void setDerivedMarkId(Integer derivedMarkId) {
		this.derivedMarkId = derivedMarkId;
	}

	public Integer getDerivedSecuType() {
		return derivedSecuType;
	}

	public void setDerivedSecuType(Integer derivedSecuType) {
		this.derivedSecuType = derivedSecuType;
	}

	public Integer getOpenMinute() {
		return openMinute;
	}

	public void setOpenMinute(Integer openMinute) {
		this.openMinute = openMinute;
	}

	public Integer getCloseMinute() {
		return closeMinute;
	}

	public void setCloseMinute(Integer closeMinute) {
		this.closeMinute = closeMinute;
	}

	public Integer getPreOpenMinute() {
		return preOpenMinute;
	}

	public void setPreOpenMinute(Integer preOpenMinute) {
		this.preOpenMinute = preOpenMinute;
	}

	public Integer getAfterHourMinute() {
		return afterHourMinute;
	}

	public void setAfterHourMinute(Integer afterHourMinute) {
		this.afterHourMinute = afterHourMinute;
	}

	private boolean duringTradingHours(int a) {
		return a >= openMinute && a <= closeMinute;
	}
	
	public boolean duringTradingHours(DatetimeMetadata dm) {
		int a = dm.getHourOfDay() * 60 + dm.getMinuteOfHour();
		return duringTradingHours(a);
	}
	
	public boolean duringTradingHoursForDelay(DatetimeMetadata dm, int delay) {
		int a = dm.getHourOfDay() * 60 + (dm.getMinuteOfHour()-delay);
		return duringTradingHours(a);
	}


	public String getMarketName() {
		return marketName;
	}

	public void setMarketName(String marketName) {
		this.marketName = marketName;
	}

	public int getExchId() {
		return exchId;
	}

	public void setExchId(int exchId) {
		this.exchId = exchId;
	}

	public int getSecuType() {
		return secuType;
	}

	public void setSecuType(int secuType) {
		this.secuType = secuType;
	}

	

	public short getIsInternational() {
		return isInternational;
	}

	public void setIsInternational(short isInternational) {
		this.isInternational = isInternational;
	}



	@Override
	public int compare(Object o1, Object o2) {
		// TODO Auto-generated method stub
		return 0;
	}

}
